//
// Created by yyancy on 2020/4/12.
//

#include <iostream>
#include "letter.hpp"


namespace demo {
    void swap(int &a, int &b) {
        int temp = a;
        a = b;
        b = temp;
    }

    struct throws {
        int age;
        std::string name;
        bool male;
    };


}

using namespace std;
int id_generator = 0;

class Intvec {
public:
    explicit Intvec(size_t num = 0)
            : m_size(num), m_data(new int[m_size]), id(id_generator++) {
        log("constructor");
    }

    ~Intvec() {
        log("destructor");
        if (m_data) {
            delete[] m_data;
            m_data = nullptr;
        }
    }

    Intvec(const Intvec &other)
            : m_size(other.m_size), m_data(new int[m_size]) {
        log("copy constructor");
        for (size_t i = 0; i < m_size; ++i)
            m_data[i] = other.m_data[i];
    }

    Intvec &operator=(const Intvec &other) {
        log("copy assignment operator");
        Intvec tmp(other);
        std::swap(m_size, tmp.m_size);
        std::swap(m_data, tmp.m_data);
        return *this;
    }

    Intvec &operator=(Intvec &&other) {
        log("move assignment operator");
        std::swap(m_size, other.m_size);
        std::swap(m_data, other.m_data);
        return *this;
    }

private:
    void log(const char *msg) {
        cout << "[" << this << "] " << "[id " << this->id << "]" << msg << "\n";
    }

    int id;
    size_t m_size;
    int *m_data;
};

const Intvec &clone(Intvec &ft) {
    Intvec *pt;
    *pt = ft;
    return *pt;
}














//namespace letter {
//    typedef struct address {
//        string name;
//        char tel[20];
//        struct address *next;
//    } ADDR;
//
//
//#define ASK(p) do{ \
//    p = (ADDR*)malloc(sizeof(ADDR)); \
//    if (p == NULL) {printf("memory fail!\n");exit(-1);} \
//}while(0);
//
//}
//using namespace letter;


int count = 20;


int menu_select(void) {
    char s[2];
    int cn = 0;
    printf("\n");
    printf("1. 输入记录\n");
    printf("2. 显示记录\n");
    printf("3. 删除记录\n");
    printf("4. 结束运行\n");
    printf("\n左边数字对应功能选择， 请选1-4: ");
    for (;;) {
        fgets(s, 2, stdin);
        while (getchar() != '\n');
        cn = atoi(s);
        if (cn < 1 || cn > 6) printf("\n输入错误， 重选1-4： ");
        else break;
    }
    return cn;
}

extern "C" void handle_menu(ADDR *top) {
    for (;;) {
        switch (menu_select()) {
            case 1:
                top = input(top);
                break;
            case 2:
                display(top);
                break;
            case 3:
                top = del(top);
                break;
            case 4:
                printf("退出操作， 再见！ \n");
                exit(0);
        }
    }
}

//extern "C" void display(ADDR *);

int main() {
    using namespace std;


//
//    Intvec v1(20);
//    Intvec v2;
//
//    auto *pv3 = new Intvec;
//
////    perror("what");
//    *pv3 = v1;
////    Intvec *v3 = new Intvec{20};
//#if 0
//    cout << "assigning lvalue...\n";
//    v2 = v1;
//    cout << "ended assigning lvalue...\n";
//    cout << "rvalue test";
//#endif
//
////    cout << "assigning rvalue...\n\n";
////    v2 = Intvec(33);
////    cout << "ended assigning rvalue...\n";
////
////
////    perror("what");
//    delete pv3;



    ADDR *top;
    ASK(top);
    top->next = NULL;
    count = 0;
    handle_menu(top);


}